package com.orangelife.mobile.myhouse.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.datatrack.DataTrack;
import com.orangelife.mobile.common.activity.OrangeLifeBaseActivity;
import com.common.jump.HouseJumper;
import com.orangelife.mobile.myhouse.adapter.HouseRentAdapter;
import com.orangelife.mobile.myhouse.entity.IndustryEntity;
import com.orangelife.mobile.util.ToastHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HouseRentActivity extends OrangeLifeBaseActivity {

    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.btnFinish)
    Button btnFinish;
    @Bind(R.id.listView)
    ListView listView;

    private String commID;
    private HouseRentAdapter mAdapter;
    private List<IndustryEntity.ApartmentsBean> mList = new ArrayList<>();
    private String applicationID;
    private Bundle mBundle;
    private final String MODULE_NAME="/IA/UPOBrowseIAInfo";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_house_rent);
        ButterKnife.bind(this);
        setAdapter();
        getIntentInfo();
        initView();
        DataTrack.browseTrack(DataTrack.APP_NAME,MODULE_NAME,null);
    }

    /**
     * 数据采集体不要删除
     * @return
     */
    public Map<String,Object> getDataTrack(){
        Map<String,Object> map=new HashMap<>();
        map.put("UI_HOST", DataTrack.APP_NAME);
        map.put("UI_PATH", MODULE_NAME);
        return map;
    }

    private void initView() {
        tvTitle.setText(getString(R.string.identity));
    }

    private void getIntentInfo() {
        mBundle = getIntent().getExtras();
        if (mBundle != null) {
            commID = mBundle.getString("commID");
            IndustryEntity ie = (IndustryEntity) mBundle.getSerializable("industry");
            if (ie != null) {
                applicationID = ie.getApplicationID();
                mList = ie.getApartments();
                if (mList != null) {
                    mAdapter.setList(mList);
                    mAdapter.notifyDataSetChanged();
                }
            }
        }
    }

    private void setAdapter() {
        mAdapter = new HouseRentAdapter(this);
        listView.setAdapter(mAdapter);
    }

    public void jumpToCert2() {
        if (commID == null) {
            ToastHelper.getInstance()._toast("请先选择小区");
        } else {
            if(mBundle==null){
                mBundle=new Bundle();
            }
            mBundle.putString("applicationID", applicationID);
            mBundle.putString("commID", commID);
            HouseJumper.jumpToTenantCert2(this, mBundle);
            DataTrack.clickTrack(DataTrack.APP_NAME,MODULE_NAME,"applyOtherHouse");
        }
    }


    @OnClick(R.id.btnFinish)
    public void onClick(View v) {
        finish();
    }

}
